using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace LCWMS
{
    public partial class w_so037 : DockContent
    {
        public w_so037()
        {
            InitializeComponent();
        }

        private void btn_query_Click(object sender, EventArgs e)
        {

            string str_sql;
            DataSet ds_waveserialno = new DataSet();
            str_sql = "select  (select max(sph.address)  from "+ main.g_space + ".so_pack_header sph,"+ main.g_space +".so_ship_wavedetail ssw "+
                    " where sph.inv_org = ssw.inv_org and sph.consignor = ssw.consignor and sph.so_no = ssw.so_no "+
                    " and a.inv_org = ssw.inv_org and a.consignor = ssw.consignor and a.wave_no = ssw.wave_no) memo "+
                    " ,a.consignor,a.wave_no,a.sku,a.serialno,a.pack_code,a.sku_name,a.pick_qty_m,convert(char(10),a.made_time,102) made_time,b.user_name maker "+
                    " from "+ main.g_space +".so_pick_waveserialno a,"+ main.g_space +".sys_user b "+
                    " where a.inv_org = b.inv_org and a.maker = b.user_id " +
                    " and  a.inv_org = '"+ main.g_org +"'";
            if(!string.IsNullOrEmpty(txt_waveno.Text.ToString()))
            {
                str_sql = str_sql + "and wave_no='"+ txt_waveno.Text.ToString().Trim()+"'";
            }
            if (!string.IsNullOrEmpty(txt_skuname.Text.ToString()))
            {
                str_sql = str_sql + "and sku_name like'%" + txt_skuname.Text.ToString().Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txt_sku.Text.ToString()))
            {
                str_sql = str_sql + "and sku='" + txt_sku.Text.ToString().Trim() + "'";
            }
            if (!string.IsNullOrEmpty(txt_serialno.Text.ToString()))
            {
                str_sql = str_sql + "and serialno='" + txt_serialno.Text.ToString().Trim() + "'";
            }
            try
            {
                if (main.dbtype == "SQL")
                    ds_waveserialno = main.dbservice.Sql_exec_selectsql(str_sql);
                else
                    ds_waveserialno = main.dbservice.oracle_exec_selectsql(str_sql);
                if(ds_waveserialno.Tables[0].Rows.Count > 0)
                {
                    this.so037_rpt1.SetDataSource(ds_waveserialno.Tables[0]);
                    crv_serialno.ReportSource = so037_rpt1;
                }
              
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to Query", main.g_info_dataset) + "!" + ee.ToString());

            } 
        }
    }
}